<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<!-- 

使用冒泡排序对整数数组 [5, 1, 4, 2, 8] 进行升序排序。

-->
<script>
    var a = [5, 1, 4, 2, 8]
    function array(a) {
        for (var i = 0; i < a.length - 1; i++) {
            for (var j = 0; j < a.length - 1 - i; j++) {
                if (a[j] > a[j + 1]) {
                    [a[j], a[j + 1]] = [a[j + 1], a[j]]
                }
            }
        }
        return a;
    }

    console.log(array(a));

</script>

</html>